package com.sakuracard.stepdemo.web.model;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

public class SearchParams {
  @Getter
  @Setter
  private Map<String, Object> params = new HashMap<>();

  @Setter
  @Getter
  private Integer page;

  @Setter
  private Integer perPage;

  public int getPerPage() {
    return this.perPage == null ? 20 : this.perPage;
  }

  public int getCurrentPage() {
    if (this.page == null || this.page < 1) {
      return 1;
    }
    return this.page;
  }

  public int getOffset() {
    return (this.getCurrentPage() - 1) * this.getPerPage();
  }

  public void initDefaults() {
  }
}
